package com.zy.oop;

import java.util.Arrays;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        int[] arr = {3,22,1,2,343,55};
        quickSort(arr, 0, arr.length - 1);
        System.out.println("排序后:");
        for (int i : arr) {
            System.out.print(i + "\t");
        }
    }

    private static void quickSort(int[] arr, int low, int high) {

        if (low < high) {

            int index = getIndex(arr, low, high);


            quickSort(arr, low, index - 1);
            quickSort(arr, index + 1, high);
        }

    }

    private static int getIndex(int[] arr, int low, int high) {

        int tmp = arr[low];
        while (low < high) {

            while (low < high && arr[high] >= tmp) {
                high--;
            }

            arr[low] = arr[high];

            while (low < high && arr[low] <= tmp) {
                low++;
            }

            arr[high] = arr[low];

        }

        arr[low] = tmp;

        return low;


    }
}
